package ${packageName};

import com.dean.system.pojo.${tableInfo.firstUpperEntityName};
import com.dean.system.service.${tableInfo.firstUpperEntityName}Service;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.dean.commons.constant.DeanOprConstant;
import com.dean.commons.dto.DeanQryPage;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
<#assign classPath="">
<#list tableInfo.tableName?split("_") as path>
    <#assign classPath=classPath+"/"+path />
</#list>
/**
*
* @Description ${tableInfo.firstUpperEntityName}Controller
* @Author dean
* @Date ${dateTime}
*/
@RestController
@RequestMapping("${classPath}")
public class ${tableInfo.firstUpperEntityName}Controller {
    private final ${tableInfo.firstUpperEntityName}Service service;

    public ${tableInfo.firstUpperEntityName}Controller(${tableInfo.firstUpperEntityName}Service service){
        this.service = service;
    }

    @PostMapping("/one/{dataId}")
    public ${tableInfo.firstUpperEntityName} one(@PathVariable("dataId") Long dataId){
        return this.service.selectById(dataId);
    }

    @PostMapping("/list")
    public PageInfo<${tableInfo.firstUpperEntityName}> list(@RequestBody String reqJsonStr) {
        JSON json = JSONUtil.parse(reqJsonStr);
        DeanQryPage qryPage = json.toBean(DeanQryPage.class);
        ${tableInfo.firstUpperEntityName} entity = json.toBean(${tableInfo.firstUpperEntityName}.class);
        return this.service.pageList(entity, qryPage.getPage(),qryPage.getLimit());
    }

    @PostMapping("/listAll")
    public List<${tableInfo.firstUpperEntityName}> listAll(${tableInfo.firstUpperEntityName} entity) {
        return this.service.selectList(entity);
    }

    @PostMapping("/insert")
    public void  insert(${tableInfo.firstUpperEntityName} entity) {
        this.service.insert(entity);
    }

    @PostMapping("/update")
    public void  update(${tableInfo.firstUpperEntityName} entity) {
        this.service.update(entity);
    }

    @PostMapping("/delete/{dataId}")
    public void delete(@PathVariable("dataId") Long dataId) {
        this.service.deleteById(dataId);
    }

    @PostMapping("/batchDelete")
    public void deleteAll(@RequestBody Long [] dataIds) {
        this.service.deleteByIds(dataIds);
    }

    @PostMapping("/batchInsert")
    public void saveAll(List<${tableInfo.firstUpperEntityName}> entities) {
        entities.foreach(entity->this.service.insert(entity));
    }

    @PostMapping("changeStatus")
    public void changeStatus(@RequestBody ${tableInfo.firstUpperEntityName} entity){
        this.service.changeStatus(entity.getDataId(),entity.getStatus());
    }
}
